package com.peanut.baby.mvp.record;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.peanut.baby.InitManager;
import com.peanut.baby.R;
import com.peanut.baby.model.RecordCategory;
import com.peanut.devlibrary.adapter.HolderAdapter;

import java.util.List;

/**
 * Created by anonymouslystudio on 2017/8/9.
 */

public class RecordCategoryGridAdapter extends HolderAdapter<RecordCategory,RecordCategoryGridAdapter.ViewHolder>{
    int cellSize;
    public RecordCategoryGridAdapter(Context context, List<RecordCategory> listData) {
        super(context, listData);
        cellSize = InitManager.getInstance().getScreenWidth() / 3;
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, RecordCategory recordCategory, int position) {
        return inflate(R.layout.layout_item_record_category_grid);
    }



    @Override
    public ViewHolder buildHolder(View convertView, RecordCategory recordCategory, int position) {
        ViewHolder holder = new ViewHolder();
        holder.container = (LinearLayout) convertView.findViewById(R.id.category_container);
        holder.icon = (ImageView) convertView.findViewById(R.id.category_icon);
        holder.name = (TextView) convertView.findViewById(R.id.category_name);
        fixCellSize(holder.container);
        return holder;
    }
    private void fixCellSize(LinearLayout container){
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)container.getLayoutParams();
        params.width = cellSize;
        params.height = cellSize;
        container.setLayoutParams(params);
    }

    @Override
    public void bindViewDatas(ViewHolder holder, RecordCategory recordCategory, int position) {
        holder.icon.setImageResource(R.drawable.icon_default_logo);
        holder.name.setText(recordCategory.name);
    }

    class ViewHolder{
        LinearLayout container;
        ImageView   icon;
        TextView    name;

    }
}
